package com.api.apiopenplatinterface.controller;

import com.api.apiopenplatclientsdk.model.User;
import com.api.apiopenplatinterface.service.NameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * description
 *
 * @title  用户
 * @author tianzhou
 * @date 2023/3/22 15:53
 */
@RestController
@RequestMapping("/name")
public class NameController {

    @Autowired
    private NameService nameService;

    @GetMapping("/getName")
    public String getNameByGet(String name) {
        return "GET的名字是" + nameService.getName(name);
    }

    @PostMapping("/getNameByPost")
    public String getNameByPost(@RequestParam  String name) {
        return "POST的名字是" + name;
    }

    @PostMapping("/getNameByPostRest")
    public String getNameByPostReslt(@RequestBody User user, HttpServletRequest httpServletRequest) {
        String accessKey = httpServletRequest.getHeader("accessKey");
        String nonce = httpServletRequest.getHeader("nonce");
        String timestamp = httpServletRequest.getHeader("timestamp");
        String sign = httpServletRequest.getHeader("sign");
        String body = httpServletRequest.getHeader("body");
        // String secretKey = httpServerRequest.getHeader("secretKey");
//        if (!"tz".equals(accessKey)) {
//            throw  new RuntimeException("无权限");
//        }
        // todo 校验时间是否超过五分钟
        // timestamp
        // todo 存储随机数 用过之后不能再用 存入redis 五分钟失效
        // nonce

        // todo 改从数据库查
//        String secretKey = "hytz";
//        String serverSign = SignUtil.genSign(body, "hytz");
//        if (!sign.equals(serverSign)) {
//            throw new RuntimeException("无权限");
//        }
        return "POSTRest的名字" + user.getName();
    }
}
